﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using FightTheDragon.Managers;

namespace FightTheDragon.GameObjects
{
    //This class is the baseobject class more for a outline for objects to inherit
    public class BaseObject
    {
        public enum Types { NONE, PLAYER, DRAGON };

        private Vector2 m_vPosition;

        public Vector2 VPosition
        {
            get { return m_vPosition; }
            set { m_vPosition = value; }
        }

        private Vector2 m_vVelocity;
        public Vector2 VVelocity
        {
            get { return m_vVelocity; }
            set { m_vVelocity = value; }
        }

        private Vector2 m_Origin;
        public Vector2 Origin
        {
            get { return m_Origin; }
            set { m_Origin = value; }
        }
        private Types m_nObjectType;

        public Types NObjectType
        {
            get { return m_nObjectType; }
            set { m_nObjectType = value; }
        }
        private float m_fWidth;

        public float Width
        {
            get { return m_fWidth; }
            set { m_fWidth = value; }
        }
        private float m_fHeight;

        public float Height
        {
            get { return m_fHeight; }
            set { m_fHeight = value; }
        }
        private string m_texture;

        public string Texture
        {
            get { return m_texture; }
            set { m_texture = value; }
        }
        private Color m_Color;

        public Color SpriteColor
        {
            get { return m_Color; }
            set { m_Color = value; }
        }
        private float m_fScale;

        public float FScale
        {
            get { return m_fScale; }
            set { m_fScale = value; }
        }
        private float m_fRotation;

        public float FRotation
        {
            get { return m_fRotation; }
            set { m_fRotation = value; }
        }

        //Default CTOR
        public BaseObject()
        {
            m_vPosition = new Vector2(0);
            m_vVelocity = new Vector2(0, 0);
            m_nObjectType = Types.NONE;
            m_fWidth = 0;
            m_fHeight = 0;
            m_texture = null;          
            m_Color = Color.White;       
            m_fScale = 1;
            m_fRotation = 0;
            m_Origin = new Vector2(0);


        }

        public virtual Rectangle GetRect()
        {
            int PosX = (int)(m_vPosition.X-m_Origin.X); //
            int PosY = (int)(m_vPosition.Y-m_Origin.Y);
            int Width = PosX + (int)(m_fWidth*m_fScale); // Scale the Width for Correct Size
            int Height = PosY + (int)(m_fHeight*m_fScale); // Scale the Height for Correct Size

           return  new Rectangle(PosX, PosY, Width, Height);
        }




        public virtual void Update(float fgameTime)
        {
            m_vPosition.X += m_vVelocity.X;
            m_vPosition.Y += m_vVelocity.Y;
            
        }




        public virtual void Render()
        {        

                GlobalContentManager.Instance.Sprites.Draw(GlobalContentManager.Instance.Texture(Texture),m_vPosition,null, m_Color,m_fRotation,
                    m_Origin,m_fScale,0,0);

        }

        public virtual bool CheckCollision(BaseObject Check)
        {

                Rectangle thisObject = this.GetRect();
                Rectangle Against = Check.GetRect();
                bool bCollide = false;

                thisObject.Intersects(ref Against, out bCollide);

                return bCollide;
        }





    }
}
